package com.cfec.ipoth_service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cfec.ipoth_service.domain.FacialAnalysis;
import com.cfec.ipoth_service.domain.TbOlders;
import com.cfec.ipoth_service.mapper.TbOldersMapper;
import com.cfec.ipoth_service.service.FacialAnalysisService;
import com.cfec.ipoth_service.mapper.FacialAnalysisMapper;
import com.cfec.ipoth_service.util.ResultData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
* @author diyu
* @description 针对表【facial_analysis(面部表情情绪分析表，通过微表情识别情绪状态)】的数据库操作Service实现
* @createDate 2025-04-20 11:37:54
*/
@Service
public class FacialAnalysisServiceImpl extends ServiceImpl<FacialAnalysisMapper, FacialAnalysis>
    implements FacialAnalysisService{

    @Resource(name = "tbOldersMapper")
    private TbOldersMapper tbOldersMapper;

    @Override
    public ResultData<Object> getAi() {
        return null;
    }

    /**
     * 获取面部表情情绪分析结果
     * @param olderIds 老人id
     * @return 面部表情情绪分析结果
     */
    @Override
    public ResultData<Object> getFaceEmotion(List<Long> olderIds) {
        ArrayList<TbOlders> tbOlders = new ArrayList<>();
        try {
            olderIds.forEach(olderId -> {
                QueryWrapper<TbOlders> QueryWrapper = new QueryWrapper<>();
                QueryWrapper.eq("older_id", olderId)
                        .eq("older_status", 1);
                TbOlders tbOldersResult = tbOldersMapper.selectOne(QueryWrapper);
                tbOlders.add(tbOldersResult);
            });
        } catch (Exception e) {
            return new ResultData<>(500, "获取面部表情情绪分析结果失败", e.getMessage());
        }
        return new ResultData<>(200, "获取面部表情情绪分析结果成功", tbOlders);
    }
}




